﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CustomsServiceRef;
    using WMS6.Web.UserControls;

    public class ImportDeclarationsRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnNewSearch;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected HtmlForm F15511;
        protected GridView gvImportDeclarationsRpt;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label ImportDeclarationsRpt;
        protected Label lblMsg;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        protected UpdatePanel up1;

        private void BindData2ImportDeclarationsRptList(ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(importDeclarationsRptQueryEntity.CurrentPage);
            DataSet ds = new DataSet();
            ds = CustomsServiceClientProxy.GetInstance().GetImportDeclarationsRptDateSet(importDeclarationsRptQueryEntity);
            base.BindData2GridView(this.gvImportDeclarationsRpt, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
            importDeclarationsRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "Y";
            string currentPageIndex = importDeclarationsRptQueryEntity.CurrentPage;
            importDeclarationsRptQueryEntity.CurrentPage = "0";
            this.gvImportDeclarationsRpt.Columns[1].Visible = false;
            this.gvImportDeclarationsRpt.AllowSorting = false;
            this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
            this.hdnActionID.Value = "";
            this.gvImportDeclarationsRpt.ShowFooter = false;
            importDeclarationsRptQueryEntity.IsGetAll = false;
            importDeclarationsRptQueryEntity.CurrentPage = currentPageIndex;
            this.SetImportDeclarationsRptQueryEntity(importDeclarationsRptQueryEntity);
            this.hdnActionID.Value = "";
            base.Export2Excel("ImportDeclarationsRpt.xls", this.gvImportDeclarationsRpt);
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
            importDeclarationsRptQueryEntity.CurrentPage = "0";
            this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
            importDeclarationsRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
            importDeclarationsRptQueryEntity.DeclarationsID = "";
            importDeclarationsRptQueryEntity.Status = "";
            importDeclarationsRptQueryEntity.OwnerID = "";
            importDeclarationsRptQueryEntity.CompanyDeclarationgsID = "";
            importDeclarationsRptQueryEntity.CreatedBy = "";
            importDeclarationsRptQueryEntity.OwnerOrderID = "";
            importDeclarationsRptQueryEntity.VerificationFormID = "";
            importDeclarationsRptQueryEntity.DeclarationsDate = "";
            this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
            if (int.Parse(importDeclarationsRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                importDeclarationsRptQueryEntity.CurrentPage = (int.Parse(importDeclarationsRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
            if (int.Parse(importDeclarationsRptQueryEntity.CurrentPage) > 0)
            {
                importDeclarationsRptQueryEntity.CurrentPage = (int.Parse(importDeclarationsRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntityEntity = this.GetImportDeclarationsRptQueryEntity();
            this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntityEntity);
        }

        private ImportDeclarationsRptQueryEntity GetImportDeclarationsRptQueryEntity()
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                return (base.PageQueryEntityViewState as ImportDeclarationsRptQueryEntity);
            }
            return (base.PageQueryEntitySession as ImportDeclarationsRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
                importDeclarationsRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
            }
        }

        protected void gvImportDeclarationsRpt_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15511", this.gvImportDeclarationsRpt);
        }

        protected void gvImportDeclarationsRpt_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblItemNoDescr"));
            }
        }

        protected void gvImportDeclarationsRpt_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = this.GetImportDeclarationsRptQueryEntity();
                importDeclarationsRptQueryEntity.SortField = e.SortExpression;
                if (importDeclarationsRptQueryEntity.SortDirection == "ASC")
                {
                    importDeclarationsRptQueryEntity.SortDirection = "DESC";
                }
                else if (importDeclarationsRptQueryEntity.SortDirection == "DESC")
                {
                    importDeclarationsRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity = new ImportDeclarationsRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    importDeclarationsRptQueryEntity.DeclarationsID = this.PreviousPage.DeclarationsID;
                    importDeclarationsRptQueryEntity.Status = this.PreviousPage.Status;
                    importDeclarationsRptQueryEntity.OwnerID = this.PreviousPage.OwnerID;
                    importDeclarationsRptQueryEntity.CompanyDeclarationgsID = this.PreviousPage.CompanyDeclarationsID;
                    importDeclarationsRptQueryEntity.CreatedBy = this.PreviousPage.CreatedBy;
                    importDeclarationsRptQueryEntity.OwnerOrderID = this.PreviousPage.OwnerOrderID;
                    importDeclarationsRptQueryEntity.VerificationFormID = this.PreviousPage.VerificationFormID;
                    importDeclarationsRptQueryEntity.DeclarationsDate = this.PreviousPage.DeclarationsDate;
                }
                else
                {
                    importDeclarationsRptQueryEntity.DeclarationsID = "";
                    importDeclarationsRptQueryEntity.Status = "";
                    importDeclarationsRptQueryEntity.OwnerID = "";
                    importDeclarationsRptQueryEntity.CompanyDeclarationgsID = "";
                    importDeclarationsRptQueryEntity.CreatedBy = "";
                    importDeclarationsRptQueryEntity.OwnerOrderID = "";
                    importDeclarationsRptQueryEntity.VerificationFormID = "";
                    importDeclarationsRptQueryEntity.DeclarationsDate = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            importDeclarationsRptQueryEntity.IsGetAll = false;
            importDeclarationsRptQueryEntity.CurrentPage = "0";
            importDeclarationsRptQueryEntity.PageSize = this.gvImportDeclarationsRpt.PageSize.ToString();
            importDeclarationsRptQueryEntity.SortField = "DECLARATIONS_DATE";
            importDeclarationsRptQueryEntity.SortDirection = "DESC";
            this.PagerFooter.PageSize = this.gvImportDeclarationsRpt.PageSize;
            if (!string.IsNullOrEmpty(base.Request.QueryString["export"]))
            {
                this.hdnActionID.Value = base.Request.QueryString["export"];
            }
            this.SetImportDeclarationsRptQueryEntity(importDeclarationsRptQueryEntity);
            this.BindData2ImportDeclarationsRptList(importDeclarationsRptQueryEntity);
            if (!string.IsNullOrEmpty(base.Request.QueryString["export"]))
            {
                this.btnExport_Click(null, null);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetImportDeclarationsRptQueryEntity(ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity)
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                base.PageQueryEntityViewState = importDeclarationsRptQueryEntity;
            }
            else
            {
                base.PageQueryEntitySession = importDeclarationsRptQueryEntity;
            }
        }

        public ImportDeclarationsRptQuery PreviousPage
        {
            get
            {
                return (ImportDeclarationsRptQuery) base.PreviousPage;
            }
        }
    }
}

